﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PSI.Models {
    /// <summary>
    /// 组织机构
    /// </summary>
    public class Org {
        public Org() {
            Children = new List<Org>();
            Expanded = true;
        }

        [JsonProperty("id")]
        public string Id { get; set; }

        /// <summary>
        /// 节点显示文本
        /// </summary>
        [JsonProperty("text")]
        public string Name { get; set; }

        /// <summary>
        /// 类似: 公司\销售部\业务一组
        /// </summary>
        [JsonProperty("fullName")]
        public string FullName { get; set; }

        [JsonProperty("parentOrgId")]
        public string ParentId { get; set; }

        [JsonProperty("parentOrgName")]
        public string ParentOrgName { get; set; }

        [JsonProperty("orgCode")]
        public string OrgCode { get; set; }

        /// <summary>
        /// 节点的子节点
        /// </summary>
        [JsonProperty("children")]
        public List<Org> Children { get; private set; }

        /// <summary>
        /// 树节点是否为子节点
        /// </summary>
        [JsonProperty("leaf")]
        public bool Leaf { get { return Children.Count == 0; } }

        /// <summary>
        /// 树节点是否展开
        /// </summary>
        [JsonProperty("expanded")]
        public bool Expanded { get; set; }

        /// <summary>
        /// 树节点是否允许展开
        /// </summary>
        [JsonProperty("expandable")]
        public bool Expandable { get; set; }

        public override string ToString() {
            return string.Format("Id = {0}, 名称 = {1}, 全名 = {2}, 编码 = {3}", Id, Name, FullName, OrgCode);
        }
    }
}